{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e8b27860",
   "metadata": {},
   "source": [
    "# What\n",
    "分类任务，支持两种模式\n",
    "1. Folder模式，需要输入`train`, `valid`两个测试集对应的目录。`labels.txt`，需要训练的label，里面每个类别一行。\n",
    "2. List模式，需要输入`train`, `valid`两个测试集对应的训练文件，每行一个样本。`labels.txt`是可选参数，里面每个类别一行。`data_pattern`一个通用的目录，与train、val中的第一列进行拼接。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7050436a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from onekey_algo.fusion.MultiTransformer.run_model import train_categorical_model as clf_main\n",
    "from collections import namedtuple\n",
    "\n",
    "# 设置参数\n",
    "model_root = r'C:/Users/onekey/Desktop/demo/models'\n",
    "train = r'C:\\Users\\onekey\\Desktop\\demo\\train/'\n",
    "val = r'C:\\Users\\onekey\\Desktop\\demo\\val'\n",
    "tests = [r'C:/Users/onekey/Desktop/demo/test1', r'C:/Users/onekey/Desktop/demo/test2']\n",
    "target_file = r'C:/Users/onekey/Desktop/demo/group.csv'\n",
    "input_dim = 1834\n",
    "bags_size = 1\n",
    "normalize = True\n",
    "# 表头是第几行，一般是0或者None，None对应的是没有\n",
    "header = 0\n",
    "\n",
    "params = dict(train=train,\n",
    "              val=val,\n",
    "              tests=tests,\n",
    "              target_file=target_file,\n",
    "              j=0,\n",
    "              input_dim=input_dim,\n",
    "              bags_size=bags_size,\n",
    "              normalize=normalize,\n",
    "              header=header,\n",
    "              gpus=[0],\n",
    "              batch_size=32,\n",
    "              model_name='Transformer',\n",
    "              epochs=20,\n",
    "              init_lr=0.01,\n",
    "              optimizer='sgd',\n",
    "              model_root=model_root,\n",
    "              add_date=False,\n",
    "              retrain='',\n",
    "              iters_start=0,\n",
    "              iters_verbose=1,\n",
    "              save_per_epoch=False,\n",
    "              pretrained=True)\n",
    "# 训练模型\n",
    "Args = namedtuple(\"Args\", params)\n",
    "clf_main(Args(**params))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d6e520b6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
